package com.xh.mybatisplus.test;

import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.digest.MD5;
import org.testng.annotations.Test;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class UniqueIdUtil {
    public static String generateUniqueId(String input) {
        try {
            MessageDigest digest = MessageDigest.getInstance("MD5");
//            MessageDigest digest = MessageDigest.getInstance("SHA-256");
            byte[] hash = digest.digest(input.getBytes(StandardCharsets.UTF_8));

            StringBuilder hexString = new StringBuilder();

            for (byte b : hash) {
                String hex = Integer.toHexString(0xff & b);
                if (hex.length() == 1) {
                    hexString.append('0');
                }
                hexString.append(hex);
            }

            return hexString.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }

        return null;
    }

    public static void main(String[] args) {
        String input1 = "Hello World";
        String input2 = "Hello Java";

        String uniqueId1 = UniqueIdUtil.generateUniqueId(input1);
        String uniqueId2 = UniqueIdUtil.generateUniqueId(input2);

        System.out.println("Unique Id 1: " + uniqueId1);
        System.out.println("Unique Id 2: " + uniqueId2);
    }

    @Test
    public void test(){
        String str = "{\"printType\":2,\"showStuGardenFlag\":true,\"showGardenOrScoreType\":1,\"wrongOrRightType\":1,\"markAnswerType\":1,\"leaveMarkType\":0}";

    }


    @Test
    public void test2(){

        String s = SecureUtil.md5("123456");
        System.out.println(s);

        MD5 md5 = new MD5();
        String s1 = md5.digestHex("123456");
        System.out.println(s1);
    }
}
